/**
 * TAFREX is Copyright (c) 2012 - Claritize.com, based on project TARTAR
 * @author Radek Strnad - radek.strnad@claritize.com
 * TARTAR is Copyright (c) 2004-2005 - University of Karlsruhe (UKA) & Jozef Stefan Institute (JSI).
 * @author: Aleksander Pivk
 * 
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 * 1. Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation and/or
 * other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY UKA & JSI "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UKA or JSI NOR ITS EMPLOYEES BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
package com.claritize.tafrex.bean;

import java.util.ArrayList;
import java.util.List;

import org.jsoup.nodes.Element;

import com.claritize.tafrex.enumeration.CellType;

/**
 * MatrixElement bean represents a matrix cell.
 */
public class MatrixCell {

    /** Original HTML element. */
    private Element htmlElement = null;

    /** Text content of the cell. */
    private String text = null;

    /** Syntactic tokens. */
    private List<SyntacticToken> tokens = new ArrayList<SyntacticToken>();

    /** Proposed cell type. */
    private CellType cellType = CellType.NO_TYPE;

    /**
     * Probability that a cell belongs to a certain CellType
     * ==> p(cellType = DATA_TYPE)=?.
     */
    private float cellTypeProbability = 0f;

    /**
     * Cell size - usually cell will span across one cell however
     * when detecting ROWSPAN, COLSPAN attribute that can differ.
     */
    private MatrixStartEndIndex cellSpan = new MatrixStartEndIndex();

    /**
     * Region that is predicted the cell belongs to.
     */
    private MatrixStartEndIndex region = new MatrixStartEndIndex();

    /**
     * @return the htmlElement
     */
    public Element getHtmlElement() {
	return htmlElement;
    }

    /**
     * @param htmlElement the htmlElement to set
     */
    public void setHtmlElement(Element htmlElement) {
	this.htmlElement = htmlElement;
    }

    /**
     * @return the text
     */
    public String getText() {
	return text;
    }

    /**
     * @param text the text to set
     */
    public void setText(String text) {
	this.text = text;
    }

    /**
     * @return the tokens
     */
    public List<SyntacticToken> getTokens() {
	return tokens;
    }

    /**
     * @param tokens the tokens to set
     */
    public void setTokens(List<SyntacticToken> tokens) {
	this.tokens = tokens;
    }

    /**
     * @return the cellType
     */
    public CellType getCellType() {
	return cellType;
    }

    /**
     * @param cellType the cellType to set
     */
    public void setCellType(CellType cellType) {
	this.cellType = cellType;
    }

    /**
     * @return the cellTypeProbability
     */
    public float getCellTypeProbability() {
	return cellTypeProbability;
    }

    /**
     * @param cellTypeProbability the cellTypeProbability to set
     */
    public void setCellTypeProbability(float cellTypeProbability) {
	this.cellTypeProbability = cellTypeProbability;
    }

    /**
     * @return the cellSpan
     */
    public MatrixStartEndIndex getCellSpan() {
	return cellSpan;
    }

    /**
     * @param cellSpan the cellSpan to set
     */
    public void setCellSpan(MatrixStartEndIndex cellSpan) {
	this.cellSpan = cellSpan;
    }

    /**
     * @return the region
     */
    public MatrixStartEndIndex getRegion() {
	return region;
    }

    /**
     * @param region the region to set
     */
    public void setRegion(MatrixStartEndIndex region) {
	this.region = region;
    }


    @Override
    public MatrixCell clone() {

	MatrixCell cell = new MatrixCell();

	cell.setCellSpan(getCellSpan().clone());
	cell.setCellType(getCellType());
	cell.setCellTypeProbability(getCellTypeProbability());
	cell.setHtmlElement(getHtmlElement().clone());
	cell.setRegion(getRegion().clone());
	cell.setText(new String(getText()));

	for (SyntacticToken token : getTokens()) {
	    cell.getTokens().add(token.clone());
	}
	return cell;

    }

}


